
package app;

import java.io.IOException;
import java.net.Socket;
import java.util.Date;

public class UserSocketConnection extends SocketConnection {
	
	public UserSocketConnection(Socket s, User u) {
		super(s);
		user = u;
	}
	
	public void doLogin() {
		getConfirm();
		sendUser();
		getIdConfirm();	
	}
	
	public User getUser() {
		return user;
	}
	
	public Date getConnDate() {
		return connDate;
	}
	
	private void getConfirm() {
		try {
			connDate = (Date)receive();
		}
		catch (Exception e) {e.printStackTrace();}
	}
	
	private void sendUser(){
		user.setIp(socket.getInetAddress());
		try {
			send(user);
		}
		catch (IOException e){e.printStackTrace();}
	}
	
	private void getIdConfirm() {
		try {
			user.setId((Long)receive());
		}
		catch (Exception e){e.printStackTrace();}
	}
	
	private User user;
	private Date connDate;
}
